package com;

import java.io.File;
import java.util.concurrent.TimeUnit;

import org.junit.Before;
import org.openqa.selenium.Alert;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.browserlaunchers.Sleeper;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

import ru.esteru.selenium.factory.WebDriverFactory;

import com.opera.core.systems.OperaDriver;


public class TestBase {

	protected WebDriver driver;
	private String useBrowser = "ch";
	
	@Before
	public void setUp() throws Exception {
			
	switch(useBrowser){

	case"ff":
	driver = WebDriverFactory.getDriver(DesiredCapabilities.firefox());
	break;

	case"ch": 
	driver = new ChromeDriver();
	//driver = WebDriverFactory.getDriver(DesiredCapabilities.chrome());
	break;

	case"ie": driver = new InternetExplorerDriver();
	break;

	case"op": driver = new OperaDriver();
	break;

	case"ap_ch": 
		ChromeOptions options = new ChromeOptions();
		options.setBinary(new File ("C:/tools/browserDrivers/chromedriver.exe"));
		options.addArguments("-no-sandbox");
		
		File file = new File("C:/tools/browserDrivers/chromedriver.exe");
		System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
		driver = new ChromeDriver();
	break;

	case"ap_ie": 
		File file1 = new File("C:/tools/browserDrivers/IEDriverServer.exe");
		System.setProperty("webdriver.ie.driver", file1.getAbsolutePath());
			driver = new InternetExplorerDriver();	
	break;

	}		
			
	driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);

		}
	
	protected void wait (int ms){
		Sleeper.sleepTight(ms);
	}
	
	protected Alert confirmIsPresent() {
		 return driver.switchTo().alert();
	}

}
